package com.restaurant.application.root.support;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;

public class RootData implements PickableBean {

    public static final String FN_CLIENTTYPE = "clientType";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_CLIENTTYPE);

    private String clientType;

    public RootData(String clientType) {
        setClientType(clientType);
    }

    public RootData() {
    }

    public RootData duplicate() {
        RootData result = new RootData();
        result.clientType = this.clientType;
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public String getClientType() {
        return clientType;
    }

    public void setClientType(String value) {
        this.clientType = value;
    }

    public RootData withClientType(String value) {
        setClientType(value);
        return this;
    }

    public RootData withClientType(String value, String defaultValue) {
        setClientType(value == null ? defaultValue : value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "clientType":
                return getClientType();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof RootData)) return false;
        return signature().equals(((RootData) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean RootData has no signature defined, no hash code or equals possible.");
    }
}
